(function() {
    function queue() {
        this.dataStore = [];
        this.listSize = 0;
        this.low = 0;
    }
    queue.prototype.clear = function(element, after) {
        delete this.dataStore;
        this.dataStore = [];
    };
    queue.prototype.length = function() {
        return this.dataStore.length;
    }
    queue.prototype.unshift = function(element) {
        this.dataStore.unshift(element);
        this.low++;
    };
    queue.prototype.pop = function() {
        this.low--;
        return this.dataStore.pop();
    }
    queue.prototype.get = function() {
        return this.dataStore[this.top - 1];
    }

    // 遍历
    queue.prototype.front = function() {
        this.low = 0;
    };

    queue.prototype.end = function() {
        this.low = this.listSize - 1;
    };

    queue.prototype.prev = function() {
        if (this.low > 0) {
            this.low--;
            return true;
        }
        return false;
    };

    queue.prototype.next = function() {
        if (this.low < this.listSize - 1) {
            this.low++;
            return true;
        }
        return false;
    };

    queue.prototype.cur = function() {
        return this.low;
    };

    queue.prototype.getElement = function() {
        return this.dataStore[this.low];
    };

    queue.prototype.removeCur = function() {
        this.dataStore.splice(this.low, 1);
        this.low--;
    };


    queue.prototype.foreach = function(callback) {
        this.front();
        var element = null;
        do {
            element = this.getElement();
            callback(this.low, element);
        } while (this.next());
    }
    window.Queue = queue;
})();